package com.sgb.kjwl.view.ui.adapter.transport;

import android.content.Context;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.CarrierDetailsEntity;
import com.sgb.kjwl.utils.NumberUtil;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
 * Time:2021/1/12
 * Author:黄淋
 * Description:
 */
public class CarriageInfoAdapter extends BaseRecycleAdapter<CarrierDetailsEntity> {

    public CarriageInfoAdapter(Context context, List<CarrierDetailsEntity> datas) {
        super(context, R.layout.item_more_carriage_info, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, CarrierDetailsEntity carrierDetailsEntity) {
        holder.setBinding(BR.viewModel, carrierDetailsEntity);

        TextView intentionLoadTime = holder.getItem().findViewById(R.id.intention_load_time);
        TextView freight = holder.getItem().findViewById(R.id.intention_freight);

        if (carrierDetailsEntity.getShipmentEndTime() == 0 ||
                carrierDetailsEntity.getShipmentStartTime() == carrierDetailsEntity.getShipmentEndTime()) {
            intentionLoadTime.setText(DateUtils.stampToDay5(carrierDetailsEntity.getShipmentStartTime()));
        } else {
            intentionLoadTime.setText(DateUtils.stampToDay5(carrierDetailsEntity.getShipmentStartTime()) + " - " + DateUtils.stampToDay5(carrierDetailsEntity.getShipmentEndTime()));
        }

        if (carrierDetailsEntity.getDiscuss() == 1) {
            freight.setText("商议");
        } else {
            freight.setText(NumberUtil.trim0(carrierDetailsEntity.getKilometre()) + "公里内"
                    + NumberUtil.trim0(carrierDetailsEntity.getFreight())
                    + carrierDetailsEntity.getFreightUnit());
        }
    }
}
